'''
Litters Use Case Tests

1) Create breeding pair for litter
2) Add litter to breeding pair (confirm data entered)
3) Add litter of empty pair (confirm data entered)
4) Remove litter

!! Parts are commented out because they expose errors in code !!
'''

from interactive import *


#1)
css("#ColonyView")
linkpart("EPO").click()
twait()

css("#ColonyMenu")
linkpart("Mice").click()
twait()

Select(css("#MouseList select")).select_by_value("1")
twait()

Edit()
css("#MouseDetail #breedingButton").click()
twait()
twait() 

New()
Done()

#2)

css("#BreedingPairList")
linkpart("BreedingPair1").click()
twait()

New()
twait()

css("#LitterDetail")
css("#LitterDetail #DateOfBirth").send_keys("2012-01-01")
css("#LitterDetail #Size").send_keys("5")
css("#LitterDetail #Comment").send_keys("this be a comment")
Done()
twait()

#find_element_by_link_text("2012-01-01")
Edit()
twait()
linkpart("2012-01-01").click()
twait()

assert(css("#LitterDetail #DateOfBirth").get_attribute("value") == "2012-01-01")
assert(css("#LitterDetail #Size").get_attribute("value") == "5")
assert(css("#LitterDetail #Comment").get_attribute("value") == "this be a comment")
twait()

#3)

Back()
twait()

linkpart("2012-01-01")
twait()

New()
css("#LitterDetail")
css("#LitterDetail #DateOfBirth").send_keys("2012-03-29")
css("#LitterDetail #Size").send_keys("25")
css("#LitterDetail #Comment").send_keys("Creating a litter without known breeding pairs")
Done()
twait()

#find_element_link_text("2012-03-29 Purchased")

Edit()
linkpart("2012-03-29").click()
twait()

assert(css("#LitterDetail #DateOfBirth").get_attribute("value") == "2012-03-29")
assert(css("#LitterDetail #Size").get_attribute("value") == "25")
assert(css("#LitterDetail #Comment").get_attribute("value") == "Creating a litter without known breeding pairs")
twait()

#4)

Back()
twait()

Back()
twait()

linkpart("Breeding Pairs").click()
twait()

linkpart("BreedingPair1").click()
twait()

Edit()
driver.execute_script("return $('#LitterList li').has (':contains(\"2012-01-01\")').find('a').has('.ui-icon-delete')[0]").click() 
alert = driver.switch_to_alert()
assert(alert.text == "Are you sure you wish to delete 2012-01-01, BreedingPair: 1?")
alert.accept()



driver.quit()
